package com.itheima.Set.TreeSet;


import java.util.Comparator;
import java.util.TreeSet;

public class MyTreeSet4 {
    public static void main(String[] args) {

    /*    TreeSet<Teacher> list=new TreeSet<>(new Comparator<Teacher>() {
            @Override
            public int compare(Teacher o1, Teacher o2) {
                //主要条件：长度升序
                int result=o1.getAge()-o2.getAge();
                //次要条件：长度相同时，按字母字典顺序升序
                 result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
                return result;
            }
        });*/

                        //lambda表达式

        TreeSet<Teacher>list=new TreeSet<>((Teacher o1,Teacher o2)->{
            //主要条件：长度升序
            int result=o1.getAge()-o2.getAge();
            ////次要条件：长度相同时，按字母字典顺序升序
             result = result == 0 ? o1.getName().compareTo(o2.getName()) : result;
             return result;
        });


        Teacher s1=new Teacher("jiu",9);
        Teacher s2=new Teacher("ling",0);
        Teacher s3=new Teacher("san",3);
        Teacher s4=new Teacher("jiu",9);
        Teacher s5=new Teacher("yao",1);
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);


        for (Teacher teacher : list) {
            System.out.println(teacher);
        }

    }
}
